import java.net.Socket;
import java.util.Scanner;

import javax.swing.JFrame;


public class ChatDevice implements Runnable
{
	Socket socket;
	Thread chatDevice;
	AcceptorListener gui;
	
	public ChatDevice(Socket socket, AcceptorListener gui)
	{
		this.socket = socket;
		chatDevice = new Thread(this);
		this.gui = gui;
		
	}

	public void start()
	{
		chatDevice.start();
	}
	
	
	public void run() 
	{
		try
		{
			
		Scanner socketIn = new Scanner(socket.getInputStream());
		
		while (true)
		{
			String line = socketIn.next();
			
			if (line.startsWith("chat"))
			{
				line = socketIn.nextLine();
				gui.getText(line);
			}
			
		}
		
		}
		catch(Exception e)
		{
			
		}
	}

}
